package com.iknight.mgr.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iknight.mgr.api.OrgService;
import com.iknight.mgr.mapper.OrgMapper;
import com.iknight.mgr.model.OrgModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by jeryzym on 2017/7/27.
 */
@Service("ikgOrgService")
public class OrgServiceImpl implements OrgService<OrgModel, String> {

    @Autowired
    private OrgMapper<OrgModel, String> orgMapper;


    public List<OrgModel> selectAll() {
        return orgMapper.selectAll();
    }


    public void changeOrgPid(String org_id, String p_org_id) {
        orgMapper.changeOrgPid(org_id, p_org_id);
    }


    public List<OrgModel> getTreeNode(String p_org_id) {
        return orgMapper.getTreeNode(p_org_id);
    }


    public void save(OrgModel record) {
        if (null == orgMapper.selectOne(record.getOrg_id())) {
            orgMapper.insert(record);
        } else {
            orgMapper.update(record);
        }
    }

    public void delete(String pkey) {
        orgMapper.delete(pkey);
    }


    public OrgModel selectOne(String pkey) {
        return orgMapper.selectOne(pkey);
    }

    public PageInfo<OrgModel> selectPage(Map<String, Object> params, int pageStart, int pageSize) {
//        return null;
        PageHelper.startPage(pageStart, pageSize, true);
        List<OrgModel> result = orgMapper.selectByCond(params);
        PageInfo<OrgModel> page = new PageInfo<OrgModel>(result);
        return page;
    }
}
